# -*- coding: utf-8 -*-
import requests#type: ignore
import json
from iamtoken import get_token

def nlp_demo():
    url = 'https://nlp-ext.cn-north-4.myhuaweicloud.com/v1/7703c099b8f5485985140d72ce89715a/machine-translation/text-translation'  # endpoint和project_id需替换
    token = get_token()
    header = {
        'Content-Type': 'application/json',
        'X-Auth-Token': token
    }
    body = {
        'text': '欢迎使用机器翻译服务',
        'from': 'zh',
        'to': 'en',
        'scene': 'common'
    }
    resp = requests.post(url, data=json.dumps(body), headers=header)
    print(resp.json())

if __name__ == '__main__':
    nlp_demo()